class NeighborSum {
public:
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    NeighborSum(vector<vector<int>>& grid)
    {
        _n = grid.size();
        _grid.resize(12, vector<int>(12, 0));
        for (int i = 1; i <= _n; i++)
            for (int j = 1; j <= _n; j++)
                _grid[i][j] = grid[i - 1][j - 1];
    }

    int adjacentSum(int value)
    {
        int x, y;
        for (x = 1; x <= _n; x++)
            for (y = 1; y <= _n; y++)
                if (_grid[x][y] == value)
                    goto h;
    h:;
        return _grid[x - 1][y] + _grid[x + 1][y] + _grid[x][y - 1] + _grid[x][y + 1];
    }

    int diagonalSum(int value)
    {
        int x, y;
        for (x = 1; x <= _n; x++)
            for (y = 1; y <= _n; y++)
                if (_grid[x][y] == value)
                    goto t;
    t:;
        return _grid[x - 1][y - 1] + _grid[x + 1][y + 1] + _grid[x - 1][y + 1] + _grid[x + 1][y - 1];
    }
private:
    vector<vector<int>> _grid;
    int _n;
};

/**
 * Your NeighborSum object will be instantiated and called as such:
 * NeighborSum* obj = new NeighborSum(grid);
 * int param_1 = obj->adjacentSum(value);
 * int param_2 = obj->diagonalSum(value);
 */